#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int t,n,L,m,V,a[maxn],d[maxn],v[maxn],p[maxn],vmax,sum[maxn],val;
template <typename T>
inline void read(T & num)
{
    T f = 1,x = 0;
    char s = getchar();
    for (; s < '0' || s > '9' ; s = getchar())
    {
        if (s == '-')
        {
            f = -f;
        }
    }
    for (; s >= '0' && s <= '9' ; s = getchar())
    {
        x = (x << 3) + (x << 1) + (s ^ '0');
    }
    num = x * f;
}
template <typename T>
inline void print(T x)
{
    if (x < 0)
    {
        x = -x;
    }
    if (x > 10)
    {
        print(x / 10);
    }
    putchar(x % 10 + '0');
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    read(t);
    while (t--)
    {
        read(n),read(m),read(L),read(V);
        vmax = 0;
        for (register int i = 1 ; i <= n ; i++)
        {
            read(d[i]),read(v[i]),read(a[i]);
        }
        for (register int i = 1 ; i <= m ; i++)
        {
            read(p[i]);
            vmax = max(vmax,p[i]);
        }
        for (register int i = 1 ; i <= n ; i++)
        {
            if (v[i] > V)
            {
                sum[i] = d[i];
                if (d[i] > vmax)
                {
                    sum[i] = -1;
                }
            }
            else if (v[i] <= V && a[i] == 0)
            {
                sum[i] = -1;
            }
            else
            {
                if (((V - v[i]) * (V - v[i])) % (2 * a[i]) == 0)
                {
                    sum[i] = d[i] + ((V - v[i]) * (V - v[i])) / (2 * a[i]);
                    if (sum[i] > vmax)
                    {
                        sum[i] = -1;
                    }
                }
                else
                {
                    sum[i] = d[i] + ((V - v[i]) * (V - v[i])) / (2 * a[i]) + 1;
                    if (sum[i] > vmax)
                    {
                        sum[i] = -1;
                    }
                }
            }
        }
        for (register int i = 1 ; i <= n ; i++)
        {
            if (sum[i] <= vmax && sum[i] != -1)
            {
                val++;
            }
        }
        print(val);
        printf(" ");
        if (m == 1)
        {
            print(0);
        }
        else
        {
            print(m - 1);
        }
        printf("\n");
    }
    return 0;
}
